home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / shell / csh543mberndt.lha / src / main.c < prev    next >
C/C++ Source or Header  |  1995-04-19  |  19KB  |  768 lines

  1. /*
  2.  * MAIN.C
  3.  *
  4.  * Matthew Dillon, 24 Feb 1986
  5.  * (c)1986 Matthew Dillon     9 October 1986
  6.  *
  7.  * Version 2.07M by Steve Drew 10-Sep-87
  8.  * Version 4.01A by Carlo Borreo & Cesare Dieni 17-Feb-90
  9.  * Version 5.00L by U. Dominik Mueller 17-Feb-91
  10.  * Version 5.20L by Andreas M. Kirchwitz (Fri, 13 Mar 1992)
  11.  *
  12.  */
  13.  
  14. #include "shell.h"
  15.  
  16.  
  17. #define CSH_VER "5"
  18. #define CSH_REV "43"
  19.  
  20.  
  21. static struct Window *getwindow(void);
  22. static void exectimer(int stop);
  23. static void set_kickversion(void);
  24. char shellcompiled[]="Compiled: "__DATE__" "__TIME__" with "COMPILER"\n";
  25.  
  26. #if 1
  27. char shellname[]    ="Csh "CSH_VER"."CSH_REV" (68030)";
  28. #else
  29. char shellname[]    ="Csh "CSH_VER"."CSH_REV" (BETA)";
  30. #endif
  31.  
  32. char shellversion[] =CSH_VER""CSH_REV;
  33. char shellvers[]    =CSH_VER"."CSH_REV;
  34. char shellv   []    ="\0$VER: csh030 "CSH_VER"."CSH_REV" "__AMIGADATE__"";
  35. char shellctr []    ="CshCounter";
  36. char shellres []    ="CshResident";
  37. char shellthere[]   ="CshLoggedIn";
  38.  
  39. char *oldtitle = NULL;
  40. char trueprompt[100];
  41. char Inline[260];
  42. extern struct ExecBase *SysBase;    /* standard fare....*/
  43. extern struct DosLibrary *DOSBase;    /* more standard fare.... */
  44. struct IntuitionBase *IntuitionBase;
  45. struct GfxBase *GfxBase;
  46. struct Library *GadToolsBase;
  47. struct Library *AslBase;        /* AMK: Asl-FileRequester replaces ARP */
  48. struct Library *BattClockBase;
  49.  
  50. struct Window *old_WindowPtr = NULL;
  51. int    oldtaskpri = -999;
  52. BPTR   OldCin;
  53. void   *PatternBase;
  54. BOOL   nologout = FALSE;
  55. BOOL   nowintitle = FALSE;
  56. struct MsgPort *acs_oldport = NULL;    /* old MsgPort */
  57.  
  58. #ifdef DO_ACS_KLUDGE
  59. /*
  60.  * - New option "-K" (Kludge) for KingCON/ToolManager, sends DOS-Paket
  61.  *    ACTION_CHANGE_SIGNAL.  Don't use this option if you have no problems.
  62.  */
  63. int    acs_kludge = 0;            /* ACTION_CHANGE_SIGNAL kludge */
  64. #endif
  65.  
  66. #ifdef MULTIUSER_SUPPORT
  67. struct muBase *muBase;     /* LILJA: Added for multiuser-support */
  68. #endif
  69.  
  70. static char *defset[]={
  71.     v_histnum,  "0",
  72.     v_titlebar, shellname,
  73.     v_hist,     "50",
  74.     v_lasterr,  "0",
  75.     v_stat,     "0",
  76.     v_path,     "RAM:,RAM:c,df0:c,df1:c,sys:system,csh:,s:",
  77.     v_rxpath,   "REXX:",
  78.     v_scroll,   "2",
  79.     v_minrows,  "34",
  80.     v_hilite,   "c7",
  81.     v_lcd,      "",
  82.     v_qcd,      "csh:csh-qcd",
  83.     v_insert,   "1",
  84.     v_abbrev,   "5",
  85.     "_terminal","",
  86.     "_man",     "csh:csh.doc",
  87.     "_version", shellversion,
  88. /*    v_nomatch,  "1",*/
  89.     v_prghash,  "csh:csh-prgs",
  90.     v_complete, "*",
  91.     NULL,       NULL
  92. };
  93.  
  94. static char *defalias[]={
  95.     "cls",  "echo -n ^l",
  96.     "dswap","cd $_lcd",
  97.     "exit", "endcli;quit",
  98.     "cdir", "%q cd $q; cls; dir",
  99.     "q",    "quit",
  100.     "rx",   "RX",
  101.     "manlist", "search -nl $_man \"    \"",
  102.     NULL,   NULL
  103. };
  104.  
  105. struct MsgPort *Console=(struct MsgPort *)-1;
  106. long ExecTimer, ExecRC;
  107.  
  108. #ifdef __SASC
  109. long __stack = 17500L;
  110. #endif
  111.  
  112. main(int argc, char *argv[])
  113. {
  114.     static ROOT locals;
  115.     BPTR fh;
  116.     int i;
  117.     char buf[10];
  118.     BOOL login=FALSE,nologin=FALSE,nocshrc=FALSE,noclrmenu=FALSE;
  119. #ifdef AZTEC_C
  120.     extern int Enable_Abort;
  121.     Enable_Abort = 0;
  122. #endif
  123.  
  124.     MyMem=salloc(4);
  125.  
  126.     if( argc==0 ) {              /* Prevent starting from workbench */
  127.         Delay(60);
  128.         exit(0);
  129.     }
  130.  
  131.     Myprocess = (struct Process *)FindTask(NULL);
  132.     OldCin    = Myprocess->pr_CIS;
  133.     Mycli     = Cli();
  134. /*    Mycli     = (struct CommandLineInterface *)((long)Myprocess->pr_CLI << 2);*/
  135.  
  136.     init_mbase();
  137.     push_locals( &locals );
  138.     initmap();
  139.  
  140.     if (!SysBase || SysBase->LibNode.lib_Version<37) {
  141.         printf("Sorry, you'll need at least V37 to run CSH.\n");
  142.         exit(20);
  143.     }
  144.  
  145.     if (!DOSBase) {
  146.         printf("No dos library\n");
  147.         exit(20);
  148.     }
  149.  
  150.     /* we do not work without it ... */
  151.     DOSBase->dl_Root->rn_Flags |= RNF_WILDSTAR;
  152.  
  153.     if (!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37L))) {
  154.         printf("No graphics library\n");
  155.         exit(20);
  156.     }
  157.  
  158.     if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37L))) {
  159.         printf("No intuition library\n");
  160.         CloseLibrary((struct Library *)GfxBase);
  161.         exit(20);
  162.     }
  163.  
  164.     if (!(AslBase=OpenLibrary("asl.library",37L))) {
  165.         printf("No asl library\n");
  166.         CloseLibrary((struct Library *)IntuitionBase);
  167.         CloseLibrary((struct Library *)GfxBase);
  168.         exit(20);
  169.     }
  170.  
  171.     if (!(GadToolsBase=OpenLibrary("gadtools.library",37L))) {
  172.         printf("No gadtools library\n");
  173.         CloseLibrary((struct Library *)AslBase);
  174.         CloseLibrary((struct Library *)IntuitionBase);
  175.         CloseLibrary((struct Library *)GfxBase);
  176.         exit(20);
  177.     }
  178.  
  179. #ifdef MULTIUSER_SUPPORT
  180.     /* LILJA: Added for multiuser-support */
  181.     muBase = (struct muBase *)OpenLibrary("multiuser.library",39);
  182. #endif
  183.  
  184.     PatternBase = NULL; /* OpenLibrary("pattern.library",5L); */
  185.     BattClockBase = OpenResource(BATTCLOCKNAME);
  186.  
  187.     set_var(LEVEL_SET,"_kick2x",(SysBase->LibNode.lib_Version>=37)?"1":"0");
  188.     set_var(LEVEL_SET,"_kick3x",(SysBase->LibNode.lib_Version>=39)?"1":"0");
  189.  
  190.     set_kickversion();
  191.  
  192.     if( !IsInteractive(Input())) {
  193.         o_bground=1;
  194.         Mycli->cli_Background=DOSTRUE;
  195.     } else
  196.         Mycli->cli_Background=DOSFALSE;
  197.  
  198.     set_var( LEVEL_SET, v_bground, (o_bground) ? "1" : "0" );
  199.  
  200.     /* We don't really need "CONSOLE:", maybe good for stderr ... */
  201.     if( fh=Open( "CONSOLE:" , MODE_NEWFILE) ) {
  202.         Console= ((struct FileHandle *)(4*fh))->fh_Type;
  203.         Close(fh);
  204.     }
  205.  
  206.     Forbid();
  207.     i=0;
  208.     /* AMK: OS20-GetVar replaces ARP-Getenv, SetVar replaces Setenv */
  209.     if ( GetVar(shellthere,buf,10,GVF_GLOBAL_ONLY|GVF_BINARY_VAR) <  0L) {
  210.         login=TRUE;
  211.         SetVar(shellthere,"1",-1L,GVF_GLOBAL_ONLY|GVF_BINARY_VAR);
  212.     }
  213.     if ( GetVar(shellres  ,buf,10,GVF_GLOBAL_ONLY|GVF_BINARY_VAR) >= 0L)
  214.         o_resident=1;
  215.     if ( GetVar(shellctr  ,buf,10,GVF_GLOBAL_ONLY|GVF_BINARY_VAR) >= 0L)
  216.         i=atoi(buf);
  217.     sprintf(buf, "%d", i+1);
  218.     /* AMK: OS20-SetVar replaces ARP-Setenv */
  219.     SetVar(shellctr, buf, -1L, GVF_GLOBAL_ONLY|GVF_BINARY_VAR);
  220.     Permit();
  221.  
  222. #ifdef AZTEC_C
  223.     stdin->_flags    |= _IONBF;    /* make sure we're set as an unbuffered tty */
  224.     stdout->_flags    |= _IONBF;    /* in case of redirection in .login */
  225.     Close( (BPTR)_devtab[2].fd);
  226.     _devtab[2].mode |= O_STDIO;
  227.     _devtab[2].fd = _devtab[1].fd;    /* set stderr to Output() otherwise */
  228.                     /* don't work with aux driver */
  229. #else
  230.     /* if( setvbuf( stdout,NULL,_IOLBF,BUFSIZ )) exit(20); */
  231.     /* setnbf( stdout ); */
  232.     /* Close( _ufbs[2] );*/
  233.     /*_ufbs[2]=_ufbs[1]; */
  234.     /* setnbf( stderr ); */
  235. #endif
  236.  
  237.     sprintf(buf,"%ld",Myprocess->pr_TaskNum);
  238.     set_var(LEVEL_SET, "_clinumber", buf);
  239.  
  240.     seterr(0);
  241.     if (Myprocess->pr_CurrentDir == NULL)
  242.         execute("cd :");
  243.     set_cwd();
  244.  
  245.     o_nowindow= 1;
  246.  
  247.     set_var(LEVEL_SET,v_prompt, (IsInteractive(Input())) ? "%c%p> ":"");
  248.  
  249.     for( i=0; defset[i]; i+=2 )
  250.         set_var( LEVEL_SET, defset[i], defset[i+1] );
  251.     for( i=0; defalias[i]; i+=2 )
  252.         set_var( LEVEL_ALIAS, defalias[i], defalias[i+1] );
  253.  
  254.     o_nowindow= 0;
  255.  
  256.     for (i = 1; i < argc; ++i) {
  257.         if (*argv[i]=='-' && (index(argv[i],'a') || index(argv[i],'t')))
  258.             o_nowindow=1;
  259.         if (*argv[i]=='-' && index(argv[i],'n'))
  260.             nologin = TRUE;
  261.         if (*argv[i]=='-' && index(argv[i],'N'))
  262.             nocshrc = TRUE;
  263.         if (*argv[i]=='-' && index(argv[i],'L'))
  264.             nologout = TRUE;
  265.         if (*argv[i]=='-' && index(argv[i],'M'))
  266.             noclrmenu = TRUE;
  267.         if (*argv[i]=='-' && index(argv[i],'W'))
  268.             nowintitle = TRUE;
  269.         if (*argv[i]=='-' && index(argv[i],'R'))
  270.             o_noraw = 1;
  271.         if (*argv[i]=='-' && index(argv[i],'w'))
  272.             o_nowindow = 1;
  273.         if (*argv[i]=='-' && (index(argv[i],'C') || index(argv[i],'c'))) {
  274.             noclrmenu  = TRUE;
  275.             nowintitle = TRUE;
  276.         }
  277.     }
  278.  
  279.     if (Mycli->cli_Background) {
  280.         o_noraw    = 1;
  281.         o_nowindow = 1;
  282.         o_vt100    = 1;
  283.     }
  284.  
  285.     if( !o_nowindow && (Mywindow=getwindow()) && IsInteractive(Input())) {
  286.         old_WindowPtr = Myprocess->pr_WindowPtr;
  287.         Myprocess->pr_WindowPtr = 0L/*Mywindow*/;
  288.         newwidth();
  289.         if (!nowintitle)
  290.             oldtitle=(char *)(Mywindow->Title);
  291.         if (!noclrmenu) {
  292.             /* clear menus, even if we are not the owner */
  293.             set_menu();
  294.         }
  295.     }
  296.  
  297.     if (login && !nologin) {
  298.         /*printf("we're the first csh today, mon ami!\n");*/
  299.         if( exists("S:.login"))
  300.             execute("source S:.login");
  301.     }
  302.  
  303.     if (!nocshrc) {
  304.         if( exists("S:.cshrc"))
  305.             execute("source S:.cshrc");
  306.     }
  307.  
  308.     {
  309.     char nam1[40],nam2[40],nam3[40];
  310.     BOOL e1,e2,e3;
  311.     strcpy(nam1,"ENVARC:"); strcat(nam1,shellctr);   e1=exists(nam1);
  312.     strcpy(nam2,"ENVARC:"); strcat(nam2,shellres);   e2=exists(nam2);
  313.     strcpy(nam3,"ENVARC:"); strcat(nam3,shellthere); e3=exists(nam3);
  314.  
  315.     if (e1 || e2 || e3) {
  316.         printf("\nWARNING: please remove the following files from ENVARC:\n\n");
  317.         if (e1)
  318.         printf("          - %s\n",shellctr);
  319.         if (e2)
  320.         printf("          - %s\n",shellres);
  321.         if (e3)
  322.         printf("          - %s\n",shellthere);
  323.         printf("\n         and reboot your system after removing the files.\n");
  324.         printf("         Never copy ENV: to ENVARC: !!\n\n");
  325.         Delay(150L);
  326.     }
  327.     }
  328.  
  329.     /* would be a nice idea to have a flag that tells if this is
  330.        a full shell or just executing some commands and the leaving */
  331.  
  332.     for (i = 1; i < argc; ++i) {
  333.         if (*argv[i]=='-') {
  334.             char *str=argv[i]+1;
  335.             for( ; *str; str++ ) {
  336.                 switch( *str) {
  337.                 case 'c':
  338.                 case 'C': execute( compile_av( argv, i+1, argc, ' ',*str=='C'));
  339.                           main_exit(Lastresult); break;
  340.                 case 'k': set_var(LEVEL_SET,v_nobreak,"1"); break;
  341. #ifdef DO_ACS_KLUDGE
  342.                 case 'K': acs_kludge = 1; break;
  343. #endif
  344.                 case 'v': Verbose=1; set_var(LEVEL_SET,v_verbose,"hs"); break;
  345.                 case 'b': oldtaskpri=Myprocess->pr_Task.tc_Node.ln_Pri;
  346.                           SetTaskPri( &Myprocess->pr_Task, -1 ); break;
  347.                 case 'f': oldtaskpri=Myprocess->pr_Task.tc_Node.ln_Pri;
  348.                           SetTaskPri( &Myprocess->pr_Task,  1 ); break;
  349.                 case 'a': o_nowindow= o_noraw= 1;
  350.                           set_var( LEVEL_SET, v_hilite, "" ); break;
  351. #if 0
  352.                 case 'm': unset_var(LEVEL_SET,v_nomatch); break;
  353. #endif
  354.                 case 'm': set_var(LEVEL_SET,v_nomatch,"1"); break;
  355.                 case 't': o_nowindow= o_vt100= o_nofastscr= 1;
  356.                           set_var( LEVEL_SET, v_hilite, "b" /*"r"*/ );
  357.                           set_var( LEVEL_SET, v_noreq, "1" );
  358.                           set_var( LEVEL_SET, "_terminal", "1" );
  359.                           set_var( LEVEL_ALIAS, "cls", "e -n ^[[0\\;0H^[[J" );
  360.                           break;
  361.                 case 's': DOSBase->dl_Root->rn_Flags |= RNF_WILDSTAR;
  362.                           break;
  363.                 case 'w': /* just don't use window pointer */
  364.                           o_nowindow = 1;
  365.                           set_var( LEVEL_SET, "_timeout", "1" ); /* GWB_TIMEOUT_LOCAL */
  366.                           break;
  367.                 case 'V': /* strict VT100 mode */
  368.                           o_vt100 = 1;
  369.                           break;
  370.                 }
  371.             }
  372.         } else {
  373.             sprintf (Inline, "source %s",argv[i]);
  374.             execute (Inline);
  375.         }
  376.     }
  377.  
  378.     /* we should do "main_exit(Lastresult);" here if
  379.        csh was called with some files to source ... */
  380.  
  381. #if 0
  382.     if( fh=Open( "CONSOLE:" , MODE_NEWFILE) ) {
  383.         if (Console != ((struct FileHandle *)(4*fh))->fh_Type)
  384.             Write(fh,"Funny Console!\n",15);
  385.         else
  386.             Write(fh,"Real Console!\n",14);
  387.         Close(fh);
  388.     }
  389.     else
  390.         printf("No Console!\n");
  391.  
  392.     Write(Input(),"Input()!\n",9);
  393.     Write(Output(),"Output()!\n",10);
  394. #endif
  395.  
  396.     if( !IsInteractive(Input()) ) {
  397.         main_exit( Lastresult );
  398.     }
  399.  
  400. #ifdef DO_ACS_KLUDGE
  401.     if (acs_kludge>0) {
  402.         BPTR bfh = Open("*", MODE_OLDFILE);
  403.         struct FileHandle *fh;
  404.         long xrslt,xioerr;
  405.         if (bfh != NULL) {
  406.             fh = BADDR(bfh);
  407.             if (fh->fh_Type != NULL) {
  408.                 xrslt = DoPkt( (void *)fh->fh_Type, ACTION_CHANGE_SIGNAL, fh->fh_Arg1, (long)&(Myprocess->pr_MsgPort), NULL,NULL,NULL);
  409.                 /* also possible instead of fh->fh_Type: Myprocess->pr_ConsoleTask */
  410.                 xioerr = IoErr();
  411.                 acs_oldport = (struct MsgPort *)xioerr;
  412.                 printf("ACS_1: DoPkt()=%ld, fh_Type=%ld, ConTask=%ld, pr_MsgPort=%ld, IoErr()=%ld\n",xrslt,(long)fh->fh_Type,(long)Myprocess->pr_ConsoleTask,(long)&(Myprocess->pr_MsgPort),xioerr);
  413.             }
  414.             Close(bfh);
  415.         }
  416.         acs_kludge = 2;
  417.     }
  418. #endif
  419.  
  420.     for (;;) {
  421.         if (breakcheck())
  422.             while (WaitForChar(Input(), 100L) || CHARSWAIT( stdin ))
  423.                 gets(Inline);
  424.         clearerr(stdin);  /* prevent acidental quit */
  425.         /*
  426.            AMK: new position of breakreset() before exec_every(),
  427.                 old position caused enforcer hits
  428.                 (do 'set _every "set cols = $(wincols)"' and
  429.                  then abort (^c) a command)
  430.         */
  431.         breakreset();
  432.         exec_every();
  433.  
  434.         { /* AMK TEST BEGIN */
  435.             char *old;
  436.             char pwd[256];
  437.  
  438.             /* no requesters when no disk is inserted */
  439.             Myprocess->pr_WindowPtr = (APTR)(-1);
  440.  
  441. #if 1
  442.             if (NameFromLock(Myprocess->pr_CurrentDir, pwd, 255L)) {
  443.                 if( !(old=get_var(LEVEL_SET, v_cwd)) )
  444.                     old="";
  445.                 if (strcmp(pwd,old)) {
  446.                     set_var(LEVEL_SET, v_lcd, old);
  447.                     set_cwd();
  448.                 }
  449.             }
  450. #else
  451.             if (!NameFromLock(Myprocess->pr_CurrentDir, pwd, 255L)) {
  452.                 fprintf(stderr,"csh.main: NameFromLock() failed\n");
  453.                 strcpy(pwd,"<unknown>");
  454.             }
  455.             if( !(old=get_var(LEVEL_SET, v_cwd)) )
  456.                 old="";
  457.             if (strcmp(pwd,old)) {
  458.                 set_var(LEVEL_SET, v_lcd, old);
  459.                 set_cwd();
  460.             }
  461. #endif
  462.             /*update_sys_var(v_cwd);*/
  463.  
  464.             Myprocess->pr_WindowPtr = o_noreq ? (APTR) -1L : 0L/*Mywindow*/;
  465.  
  466.         } /* AMK TEST BEGIN */
  467.  
  468.         update_sys_var(v_titlebar);
  469.         update_sys_var(v_prompt);
  470.         /*
  471.            AMK: old position of breakreset(), causes enforcer hits
  472.                 (do 'set _every "set cols = $(wincols)"' and
  473.                  then abort (^c) a command)
  474.         */
  475.         breakreset();
  476. #if RAW_CONSOLE
  477.         if (Quit || !rawgets(Inline, disable ? "_ " : trueprompt)) main_exit(0);
  478. #else
  479.         printf("%s", disable ? "_ " : trueprompt);
  480.         fflush(stdout);
  481.         if (Quit || !gets(Inline)) main_exit(0);
  482. #endif
  483.         breakreset();
  484.  
  485. #if 1
  486.         /* start/stop timer only if non-empty command line */
  487.  
  488.         if (*Inline && strlen(Inline)>0) {
  489.             exectimer(0);
  490.             ExecRC = exec_command(Inline);
  491.             exectimer(1);
  492.         }
  493. #else
  494.         /* start/stop timer for every command  */
  495.  
  496.         exectimer(0);
  497.         if (*Inline) ExecRC=exec_command(Inline);
  498.         exectimer(1);
  499. #endif
  500.     }
  501. }
  502.  
  503.  
  504. void
  505. main_exit(n)
  506. {
  507.     int i;
  508.     char buf[10];
  509.  
  510.     /* AMK: OS20-GetVar replaces ARP-Getenv */
  511.     GetVar(shellctr,buf,10L,GVF_GLOBAL_ONLY|GVF_BINARY_VAR);
  512.     i=atoi(buf);
  513.     sprintf(buf,"%d",i-1);
  514.     /* AMK: OS20-SetVar replaces ARP-Setenv */
  515.     SetVar(shellctr, buf, -1L, GVF_GLOBAL_ONLY|GVF_BINARY_VAR);
  516.  
  517. #ifdef DO_ACS_KLUDGE
  518.     if (acs_kludge>0) {
  519.         BPTR bfh = Open("*", MODE_OLDFILE);
  520.         struct FileHandle *fh;
  521.         long xrslt,xioerr;
  522.         if (bfh != NULL) {
  523.             fh = BADDR(bfh);
  524.             if (fh->fh_Type != NULL) {
  525.                 xrslt = DoPkt( (void *)fh->fh_Type, ACTION_CHANGE_SIGNAL, fh->fh_Arg1, (long)acs_oldport, NULL,NULL,NULL);
  526.                 /* also possible instead of fh->fh_Type: Myprocess->pr_ConsoleTask */
  527.                 xioerr = IoErr();
  528.                 printf("ACS_2: DoPkt()=%ld, fh_Type=%ld, ConTask=%ld, oldport=%ld, IoErr()=%ld\n",xrslt,(long)fh->fh_Type,(long)Myprocess->pr_ConsoleTask,(long)acs_oldport,xioerr);
  529.             }
  530.             Close(bfh);
  531.         }
  532.         acs_kludge = 0;
  533.     }
  534. #endif
  535.  
  536.     if( !nowintitle && oldtitle )
  537.         SetWindowTitles(Mywindow,oldtitle,(char *)-1);
  538.     if( oldtaskpri != -999 )
  539.         SetTaskPri(&Myprocess->pr_Task,oldtaskpri);
  540.  
  541.     if (Mywindow)
  542.         Myprocess->pr_WindowPtr = old_WindowPtr;
  543.  
  544.     for (i=1; i<MAXMYFILES; i++) myclose(i);
  545.  
  546.     /* no effect if AnzMenus==0 (no menus in use) */
  547.     remove_menu();
  548.  
  549. #ifdef MULTIUSER_SUPPORT
  550.     /* LILJA: Added for multiuser-support */
  551.     if (muBase) CloseLibrary((struct Library *)muBase);
  552. #endif
  553.  
  554.     if (PatternBase) CloseLibrary( PatternBase );
  555.     CloseLibrary((struct Library *)GadToolsBase);
  556.     CloseLibrary((struct Library *)AslBase);
  557.     CloseLibrary((struct Library *)IntuitionBase);
  558.     CloseLibrary((struct Library *)GfxBase);
  559.     exit(n);
  560. }
  561.  
  562.  
  563. #if 1
  564. static void
  565. exectimer(int stop)
  566. {
  567.     struct DateStamp dss;
  568.     static struct DateStamp last;
  569.  
  570.     DateStamp(&dss);
  571.     if (stop) {
  572.         ExecTimer = dss.ds_Minute*6000 + 2*dss.ds_Tick;
  573.         ExecTimer += (dss.ds_Days-last.ds_Days)*6000*1440;
  574.         ExecTimer -= last.ds_Minute*6000 + 2*last.ds_Tick;
  575.     }
  576.     else
  577.         last = dss;
  578. }
  579. #else
  580. static void
  581. exectimer(int stop)
  582. {
  583.     struct DateStamp dss;
  584.     static long lasttime;
  585.     long time;
  586.  
  587.     DateStamp(&dss);
  588.     time=dss.ds_Minute*6000+2*dss.ds_Tick;   /* 2 = 100/TickPerSec   */
  589.     if( stop )
  590.         ExecTimer=time-lasttime;
  591.     else
  592.         lasttime=time;
  593. }
  594. #endif
  595.  
  596.  
  597. /* print break message only once */
  598. static BOOL dobreak_output = TRUE;
  599.  
  600. int
  601. breakcheck()
  602. {
  603.     return !o_nobreak && SetSignal(0L,0L) & SIGBREAKF_CTRL_C;
  604. }
  605.  
  606. void
  607. breakreset()
  608. {
  609.     /* We reset CTRL_E here for GMD's foreach() hack ... */
  610.     /* Why not just reset CTRL_F also -- for completeness? :) */
  611.  
  612.     SetSignal(0L, SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D|SIGBREAKF_CTRL_E);
  613.     dobreak_output = TRUE;
  614. }
  615.  
  616. dobreak()
  617. {
  618.     if (breakcheck()) {
  619.         if (dobreak_output) {
  620.             printf("^C\n");
  621.             dobreak_output = FALSE;
  622.         }
  623.         return(1);
  624.     }
  625.     return(0);
  626. }
  627.  
  628. /* this routine causes manx to use this Chk_Abort() rather than it's own */
  629. /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
  630. /* is zero).  Since we want to check for our own ^C's             */
  631.  
  632. long
  633. Chk_Abort()
  634. {
  635.     return(0);
  636. }
  637.  
  638. void
  639. _wb_parse()
  640. {
  641. }
  642.  
  643. do_howmany()
  644. {
  645.     char buf[10];
  646.  
  647.     /* AMK: OS20-GetVar replaces ARP-Getenv */
  648.     GetVar(shellctr, buf, 10L, GVF_GLOBAL_ONLY|GVF_BINARY_VAR);
  649.     printf("Shell(s) running: %s\n",buf);
  650.     return 0;
  651. }
  652.  
  653. static void set_kickversion(void)
  654. {
  655.     struct Library *verlib;
  656.     static char verstr[10];
  657.     if (verlib = OpenLibrary("version.library",0)) {
  658.         sprintf(verstr,"%d",verlib->lib_Version);
  659.         CloseLibrary(verlib);
  660.     }
  661.     else
  662.         sprintf(verstr,"%d",SysBase->LibNode.lib_Version);
  663.     set_var(LEVEL_SET,"_kick",verstr);
  664. }
  665.  
  666. #if 1
  667. static struct Window *
  668. getwindow(void)
  669. {
  670.     struct Window *win = NULL;
  671.  
  672.     if( o_nowindow )
  673.         return NULL;
  674.  
  675.     if( IsInteractive(Output()) )
  676.         Write(Output(),"",1);     /*    make window appear */
  677.  
  678.     if( isconsole(Output()) && Output() ) {
  679.         if ( ((struct FileHandle *)BADDR(Output()))->fh_Type ) {
  680.             struct InfoData *infodata;
  681.             infodata=(void *)SAllocMem((long)sizeof(struct InfoData),MEMF_CLEAR|MEMF_PUBLIC);
  682.             if (DoPkt((void *)((struct FileHandle *)BADDR(Output()))->fh_Type,ACTION_DISK_INFO,((LONG)infodata)>>2,NULL,NULL,NULL,NULL)) {
  683.                 win=(struct Window *)infodata->id_VolumeNode;
  684.             }
  685.             FreeMem(infodata,sizeof(struct InfoData));
  686.         }
  687.         if( win==NULL )
  688.             o_nowindow=1;
  689.     }
  690.  
  691.     newwidth();
  692.  
  693.     return win;
  694. }
  695. #else
  696. static struct Window *
  697. getwindow(void)
  698. {
  699.     struct Window *win = NULL;
  700.  
  701.     if( o_nowindow )
  702.         return NULL;
  703.     if( isconsole(Output()))
  704.         Write(Output(),"",1);     /*    make window appear */
  705.     if( Myprocess->pr_ConsoleTask ) {
  706.         struct InfoData *infodata;
  707.         infodata=(void *)SAllocMem((long)sizeof(struct InfoData),MEMF_CLEAR|MEMF_PUBLIC);
  708.         if (DoPkt((void *)Myprocess->pr_ConsoleTask,ACTION_DISK_INFO,((LONG)infodata)>>2,NULL,NULL,NULL,NULL)) {
  709.             win=(struct Window *)infodata->id_VolumeNode;
  710.         }
  711.         FreeMem(infodata,sizeof(struct InfoData));
  712.         if( win==NULL )
  713.             o_nowindow=1;
  714.     }
  715.     newwidth();
  716.     return win;
  717. }
  718. #endif
  719.  
  720. #ifdef LATTICE
  721.  
  722. int
  723. setenv( char *var, char *val )
  724. {
  725.     char *buf=salloc(strlen(var)+strlen(val)+10);
  726.     sprintf(buf, "%s=%s", var, val );
  727.     Free(buf);
  728.     return putenv(buf);
  729. }
  730.  
  731. __regargs int __chkabort(void) { return(0); }
  732.  
  733. #endif
  734.  
  735. #ifdef _DCC
  736. void
  737. swapmem(void *_s1, void *_s2, size_t _n)
  738. {
  739.     char t, *s1=_s1, *s2=_s2;
  740.     int  i;
  741.  
  742.     for( i=0; i<_n; i++ )
  743.         t = *s1; *s1++ = *s2; *s2++=t;
  744. }
  745.  
  746. int
  747. setenv( char *var, char *val )
  748. {
  749.     BPTR fh;
  750.     char buf[40];
  751.     sprintf(buf,"ENV:%s",var );
  752.  
  753.     if( fh=Open(buf,MODE_NEWFILE) ) {
  754.         Write(fh,val,strlen(val));
  755.         Close(fh);
  756.     }
  757. }
  758.  
  759. int
  760. rand()
  761. {
  762.     return 0;
  763. }
  764.  
  765. _waitwbmsg() {return 0;};
  766.  
  767. #endif
  768.